import { fileURLToPath, URL } from 'node:url'

import vue from '@vitejs/plugin-vue'
import { defineConfig } from 'vite'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
  server: {
    proxy: {
      '/api': {
        target: 'http://localhost:8080',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path
      },
      '/api/upload': {
        target: 'http://localhost:8080',
        changeOrigin: true,
        secure: false,
        ws: true,
        onProxyReq: (proxyReq) => {
          proxyReq.removeHeader('Content-Length');
          proxyReq.removeHeader('Origin');
        }
      },
      '/api/files': {
        target: 'http://localhost:8080',
        changeOrigin: true,
        secure: false
      }
    },
    cors: true
  }
})
